<div data-controller="new-project">
  <%= form_with(model: project, data: { turbo: false }) do |form| %>
    <h2 class="text-2xl font-bold">Create a new project from a container registry</h2>
    <%= link_to(
      "Deploy from Git repository instead →",
      new_project_path(provider: Provider::GITHUB_PROVIDER),
      class: "inline-block mt-2 underline underline-offset-4 text-blue-300 hover:text-blue-200 text-sm",
    ) %>
    <hr class="mt-3 mb-4 border-t border-base-300" />

    <%= render "shared/error_messages", resource: form.object %>

    <div class="space-y-8">
      <%= render(FormFieldComponent.new(
        label: "Name",
        description: "A unique name for your project, only lowercase letters, numbers, and hyphens are allowed."
      )) do %>
        <%= form.text_field :name, class: "input input-bordered w-full focus:outline-offset-0", autofocus: true, required: true %>
        <label class="label">
          <span class="label-text-alt">* Required</span>
        </label>
      <% end %>

      <%= render(FormFieldComponent.new(
        label: "Cluster",
        description: "The cluster to deploy your project to."
      )) do %>
        <%= form.collection_select :cluster_id, current_account.clusters.running, :id, :name, {}, { class: "select select-bordered w-full" } %>
        <label class="label">
          <span class="label-text-alt">* Required</span>
        </label>
      <% end %>

      <%= render(FormFieldComponent.new(
        label: "Container Registry Credentials",
        description: "The credentials to use to connect to your container registry."
      )) do %>
        <%= render "projects/create/select_credentials", form:, selectable_providers: %>
      <% end %>

      <%= render(FormFieldComponent.new(
        label: "Container Registry Repository",
        description: "The image to pull from your container registry."
      )) do %>
        <%= form.text_field(
          :repository_url,
          class: "input input-bordered w-full focus:outline-offset-0",
          placeholder: "accountname/repo",
        ) %>
      <% end %>

      <%= render(FormFieldComponent.new(
        label: "Predeploy command",
        description: "The command to run before deploying the project. This is useful for running migrations or other setup commands."
      )) do %>
        <%= form.text_field :predeploy_command, class: "input input-bordered w-full focus:outline-offset-0" %>
      <% end %>
    </div>

    <div class="form-footer">
      <%= form.button "Submit", class: "btn btn-primary" %>

      <% if form.object.new_record? %>
        <%= link_to t("cancel"), projects_path, class: "btn btn-secondary", data: { turbo: false } %>
      <% else %>
        <%= link_to t("cancel"), project_path(@project), class: "btn btn-secondary", data: { turbo: false } %>
      <% end %>
    </div>
  <% end %>
</div>